package com.ls.lserp.modules.finance.service;






import java.text.ParseException;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ls.lserp.common.persistence.Page;
import com.ls.lserp.common.service.CrudService;
import com.ls.lserp.common.utils.DateUtils;
import com.ls.lserp.common.utils.ResourcesUtil;
import com.ls.lserp.dbaccess.Entity.FinanceEntity;
import com.ls.lserp.dbaccess.Entity.OgnizationSettlementEntity;
import com.ls.lserp.modules.finance.dao.InitFinanceDao;
import com.ls.lserp.modules.finance.entity.InitFinance;
import com.ls.lserp.modules.order.entity.BigcargoOrder;
import com.ls.lserp.modules.order.entity.SizeColorQuantity;
import com.ls.lserp.modules.setting.entity.Ognization;
import com.ls.lserp.modules.sys.entity.Sequence;
import com.ls.lserp.modules.sys.utils.SequenceUtil;
import com.ls.lserp.modules.sys.utils.UserUtils;
@Service
@Transactional(readOnly = false)
public class InitFinanceService extends CrudService<InitFinanceDao,OgnizationSettlementEntity>{

	
	
	@Autowired
    private InitFinanceDao initFinanceDao;
	    /**
		 * 查询父项
		 * @param page
		 * @param user
		 * @return
		 */
	    public Page<OgnizationSettlementEntity> findList(Page<OgnizationSettlementEntity> page, OgnizationSettlementEntity settlementEntity) {
	        // 生成数据权限过滤条件（dsf为dataScopeFilter的简写，在xml中使用 ${sqlMap.dsf}调用权限SQL）
	        //designOption.getSqlMap().put("dsf", dataScopeFilter(user.getCurrentUser(), "o", "a"));
	        // 设置分页参数
	    	settlementEntity.setPage(page);
	        // 执行分页查询
	        page.setList(initFinanceDao.findList(settlementEntity));
	        return page;
	    }
	    /**
		 * 新增/修改一条数据
		 * @param user
	     * @throws Exception 
		 */
	    @Transactional(readOnly = false)
	    public void saveInitFinance(OgnizationSettlementEntity settlementEntity) throws Exception {
	    	// 判断新建编辑
	    			//若为null 执行插入语句（新建）
	    			if (settlementEntity.getId()==null){
	    				settlementEntity.preInsert();
	    				settlementEntity.setFinancePeriodStr("INIT");
	    				initFinanceDao.insert(settlementEntity);
	    			// 编辑
	    			}else{
	    				settlementEntity.preInsert();
	    				initFinanceDao.update(settlementEntity);
	    			}	
	    }
	    /**
		 * 获取机构集
		 * 
		 * @param user
		 * @return
		 */
	    public List<Ognization> findOgnizationList(){
	    	
	    	return initFinanceDao.findOgnizationList();
	    	
	    }
	    /**
		 * 获取会计科目集
		 * 
		 * @param user
		 * @return
		 */
	    public List<InitFinance> findItemList(){
	    	
	    	return initFinanceDao.findItemList();
	    	
	    }
	    /**
		 * 查询机构数据
		 * 
		 * @param user
		 * @return
		 */
	    public FinanceEntity getOgnizationInfo(FinanceEntity financeEntity){
	    	
	    	return initFinanceDao.getOgnizationInfo(financeEntity);
	    	
	    }
	    
	    /**
		 * 查存
		 * 
		 * @param ognizationId
		 * @return
		 */
	    public OgnizationSettlementEntity getByOgnizationId(long ognizationId){
	    	
	    	return initFinanceDao.getByOgnizationId(ognizationId);
	    	
	    }
	    
}
